<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="用户ID" prop="uid">
        <el-input
          v-model="queryParams.uid"
          placeholder="请输入用户ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户ID" prop="uid" style="display: none">
        <el-input placeholder="请输入用户ID" clearable size="small" />
      </el-form-item>
      <el-form-item label="查询状态" prop="canatm">
        <el-select v-model="queryParams.checked" clearable placeholder="请选择">
          <el-option
            v-for="item in canatmOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <!-- <el-form-item label="注册时间" prop="createTime">
        <DatePicker v-model="ctime" :timevalue1="ctime"></DatePicker>
      </el-form-item> -->
      <el-form-item style="display: block">
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['ds:user:add']"
        >
          新增</el-button
        >
      </el-col> -->

      <!-- <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['ds:user:export']"
          >导出</el-button>
        </el-col> -->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="userList"
      @selection-change="handleSelectionChange"
      border
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" min-width="80">
        <template slot-scope="scope">
          <div>
            <div>{{ scope.row.id }}</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="用户ID" align="center" min-width="80">
        <template slot-scope="scope">
          <div>
            <div>{{ scope.row.uid }}</div>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="消费金额" align="center" min-width="180">
        <template slot-scope="scope">
          <div>
            <div>{{ scope.row.content }}</div>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="未分红" align="center" min-width="100">
        <template slot-scope="scope">
          <div>
            <div>{{ scope.row.shengmoney }}</div>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="已分红" align="center" min-width="100">
        <template slot-scope="scope">
          <div>
            <div>{{ scope.row.maxmoney }}</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="总贡献值" align="center" min-width="100">
        <template slot-scope="scope">
          <div>
            <div>{{ scope.row.allmoney }}</div>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="入单时间" align="center" min-width="160">
        <template slot-scope="scope">
          <div>
            <div>{{ scope.row.addDate }}</div>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="解锁时间" align="center" min-width="180">
        <template slot-scope="scope">
          <div>
            <div>{{ scope.row.dividendDate }}</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="解锁状态" align="center" min-width="100">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.checked == 1"
            @click="deblockingFullCard(scope.row)"
            type="success"
            v-hasPermi="['ds:fullCard:unlock']"
            >解锁</el-button
          >
          <el-button v-else-if="scope.row.checked == 4" type="info"
            >已解锁</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { queryFullCard, deblockingFullCard } from "@/api/ds/user";
import { listprice } from "@/api/ds/price";
import { getToken } from "@/utils/auth";
import ImageUpload from "@/components/ImageUpload";
import DatePicker from "@/components/DatePicker";
import valid from "../../../utils/validator";

export default {
  name: "User",
  components: {
    ImageUpload,
    DatePicker,
  },
  directives: {},
  data() {
    return {
      ctime: ["2022-10-21 00:00:00"], //搜索框 时间选择器数据
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户信息表格数据
      userList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        uid: null,
        checked: 1,
        // params:['2022-10-21 00:00:00'],
      },
      // 表单参数
      form: {},
      productList: [], // 产品数据
      deblocking: true, //解锁开关
      canatmOptions: [
        { value: 1, label: "未解锁" },
        { value: 4, label: "已解锁" },
      ],
    };
  },
  computed: {
    formatNumber() {
      return (num) => {
        if (num) {
          num = num + "";
          let index = num.indexOf(".");
          if (index !== -1) {
            num = num.substring(0, 2 + index + 1);
          } else {
            num = num.substring(0);
          }
          return parseFloat(num).toFixed(2);
        } else {
          return "0.00";
        }
      };
    },
  },
  created() {
    // this.getProductData();

    this.getList();
    // this.getPriceList();
  },
  mounted() {
    // const self = this;
    // this.$nextTick(() => {
    //   const iframe = document.getElementById("iframe");
    // });
  },
  methods: {
    addDateRange1(params, dateRange, propName) {
      var search = params;
      search.params = {};
      if (null != dateRange && "" != dateRange) {
        if (typeof propName === "undefined") {
          search.params["beginTime"] = dateRange[0];
          search.params["endTime"] = dateRange[1];
        } else {
          search.params["begin" + propName] = dateRange[0];
        }
      }
      return search;
    },
    /** 查询用户信息列表 */
    getList() {
      this.loading = true;
      // let that = this;
      // this.queryParams.create_time = this.ctime[0]
      // this.queryParams.endTime = this.ctime[1]

      let q = this.addDateRange1(this.queryParams, this.ctime, "");

      queryFullCard(q).then((response) => {
        this.userList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 表单重置
    reset() {
      this.form = {
        uid: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.uid);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    // 解锁油卡
    deblockingFullCard(row) {
      this.$confirm("确认解锁油卡吗?", "解锁", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      }).then(() => {
        this.loading = true;
        try {
          deblockingFullCard({ id: row.id }).then((res) => {
            if (res.code === 200 && res.msg == "解锁成功") {
              this.loading = false;
              this.msgSuccess("解锁成功");
              this.getList();
            }
          });
        } catch (error) {
          this.loading = false;
        }
      });
    },
  },
};
</script>
<style>
.el-message-box__btns {
  padding: 5px 15px 0;
  text-align: right;
  display: flex;
  justify-content: space-between;
}
</style>

<style lang="scss" scoped>
.el-form-item {
  margin-bottom: 0.5%;
}

.flex {
  display: flex;
  align-items: center;
}

.el-icon-check {
  font-size: 24px;
  color: green;
}

.el-icon-close {
  font-size: 24px;
  color: red;
}

.titleClass {
  background: lightgray;
  text-align: center;
  font-size: 18px;
  padding: 1%;
}

.titleContentClass {
  text-align: center;
  color: red;
  border: 1px solid lightgray;
  font-size: 18px;
  padding: 1%;
}
</style>
